package com.hackerrank.contests.codesprint5.challenges.matrixtracing;

import java.util.Scanner;

public class Solution {
	private static final int MAX = 1000000007;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int m = in.nextInt(), n = in.nextInt(), mr = Math.min(m, n), w[] = new int[mr];
			w[0] = 1;
			for(int c = n - 2; c >= 0; c--) {
				int nw[] = new int[mr];
				nw[0] = w[0];
				for(int i = 1; i < Math.min(n - c, mr); i++)
					nw[i] = (w[i - 1] + w[i]) % MAX;
				w = nw;
			}
			for(int r = m - 2; r >= 0; r--) {
				int nw[] = new int[mr];
				for(int i = 0; i < Math.min(r + 1, mr); i++) {
					nw[i] = w[i];
					if(i < nw.length - 1)
						nw[i] = (nw[i] + w[i + 1]) % MAX;
				}
				w = nw;
			}
			System.out.println(w[0]);
		}
	}
}
